﻿using System;
using System.Net;

using System.Collections.ObjectModel;
using System.Xml;
using System.IO;

using System.Linq;
using NCT.Entity;
using System.Xml.Linq;
using System.Xml;
using System.Collections.Generic;

namespace NCT.DataAccessComponents
{
    public class XMLAction
    {
        public static ListItem ItemsParser(string xml)
        {
            ListItem li = new ListItem();
            XDocument itemXML = XDocument.Parse(xml);
            var data = from c in itemXML.Descendants("item")
                        select new Item
                        {
                            Type = (string)c.Element("class").Value,
                            Key = (string)c.Element("key").Value,
                            Name = (string)c.Element("name").Value,
                            Url = (string)c.Element("url").Value,
                            Singer = (string)c.Element("singer").Value,
                            Poster = (string)c.Element("poster").Value,
                            Liked = (string)c.Element("liked").Value,
                            Listen = (string)c.Element("listen").Value,
                            ImageUrl = (string)c.Element("imageUrl").Value
                          
                        };
            foreach (var x in data)
            {
                li.Items.Add( (Item)(object) x);
            }
            
            return li;   
        }
        

    }
}
